def dispach(s_k, p_num,p_c_t,p_s_t,t_t):
    
    p_s_t_left = {} # process left service time
    now_time = 0
    
    p_f_t = {} # process finish time
    
    if s_k == 1: # FCFS
        for name, c_t in p_c_t.items():
            while c_t > now_time:
                now_time += 1
            now_time += p_s_t[name]
            p_f_t[name] = now_time
        for name, s_t in p_s_t.items():
            print("process ", name, " finish at ", p_f_t[name], ", turnaround time is ", p_f_t[name] - p_c_t[name],
                  ", normalize turnaround time is ", (p_f_t[name] - p_c_t[name]) / s_t)
    elif s_k == 2: # RR(q=1)
        t_s = 1 # time slicing
        p_s_t_left = p_s_t.copy()
        del_name = []
        while t_t!=now_time :
            for name, s_t in p_s_t_left.items():
                if p_c_t[name] <= now_time:
                    if s_t > t_s:
                        p_s_t_left[name] -= t_s
                        now_time += t_s
                    else :
                        now_time += s_t
                        p_s_t_left[name] = 0  
                        p_f_t[name] = now_time
                        del_name.append(name)
            for name in del_name:
                del p_s_t_left[name]
            del_name.clear()
        for name, s_t in p_s_t.items():
            print("process ", name, " finish at ", p_f_t[name], ", turnaround time is ", p_f_t[name] - p_c_t[name],
                  ", normalize turnaround time is ", (p_f_t[name] - p_c_t[name]) / s_t)
    elif s_k == 3: # SPN
        p_c_t_copy = p_c_t.copy()
        while t_t!=now_time:
            min_p = ["", 9999999]  # min service time in come processes
            for name, c_t in p_c_t_copy.items():
                if c_t <= now_time:
                    if p_s_t[name]<min_p[1]:
                        min_p[0] = name
                        min_p[1] = p_s_t[name]
            now_time += min_p[1]
            p_c_t_copy.pop(min_p[0])
            p_f_t[min_p[0]] = now_time
        for name, s_t in p_s_t.items():
            print("process ", name, " finish at ", p_f_t[name], ", turnaround time is ", p_f_t[name] - p_c_t[name],
                  ", normalize turnaround time is ", (p_f_t[name] - p_c_t[name]) / s_t)
    elif s_k == 4: # SRT
        p_s_t_left = p_s_t.copy()
        p_c_t_copy = p_c_t.copy()
        while t_t!=now_time:
            min_p = ["", 9999999]  # min service time in come processes
            for name, c_t in p_c_t_copy.items():
                if c_t <= now_time:
                    if p_s_t_left[name]<min_p[1]:
                        min_p[0] = name
                        min_p[1] = p_s_t_left[name]
            now_time += 1
            p_s_t_left[min_p[0]] -= 1
            if p_s_t_left[min_p[0]] == 0:
                p_c_t_copy.pop(min_p[0])
                p_f_t[min_p[0]] = now_time
        for name, s_t in p_s_t.items():
            print("process ", name, " finish at ", p_f_t[name], ", turnaround time is ", p_f_t[name] - p_c_t[name],
                  ", normalize turnaround time is ", (p_f_t[name] - p_c_t[name]) / s_t)
    elif s_k == 5: # HRRN
        p_c_t_copy = p_c_t.copy()
        while t_t!=now_time:
            max_p = ["", 0]  # max normalized turnaround time
            for name, c_t in p_c_t_copy.items():
                if c_t <= now_time:
                    if (now_time-c_t)/p_s_t[name]+1 > max_p[1]:
                        max_p[0] = name
                        max_p[1] = (now_time-c_t)/p_s_t[name]+1
            now_time += p_s_t[max_p[0]]
            p_c_t_copy.pop(max_p[0])
            p_f_t[max_p[0]] = now_time
        for name, s_t in p_s_t.items():
            print("process ", name, " finish at ", p_f_t[name], ", turnaround time is ", p_f_t[name] - p_c_t[name],
                  ", normalize turnaround time is ", (p_f_t[name] - p_c_t[name]) / s_t)
def main():
    p_c_t = {} # process come time
    p_s_t = {} # process service time
    p_num = int(input("please input the number of process:\n"))
    print("please input processs name, process come time, process service time:")
    for i in range(p_num): # get data
        p_obj = list(input().split( ))
        # print(p_obj)
        p_c_t[p_obj[0]] = int(p_obj[1])
        p_s_t[p_obj[0]] = int(p_obj[2])
    t_t = sum(p_s_t.values()) # total times
    while True :
        s_k = int(input("please choose the kind of service:\n1.FCFS\n2.RR(q=1)\n3.SPN\n4.SRT\n5.HRRN\n0.EXIT\n"))
        if s_k == 0:
            break
        dispach(s_k,p_num,p_c_t,p_s_t,t_t)

main()

"""
data:
A 0 3
B 2 6
C 4 4
D 6 5
E 8 2
"""